package com.zhuiYun.project.api.slideshow.controller;

import com.alibaba.fastjson.JSONArray;
import com.zhuiYun.project.annotation.OptLog;
import com.zhuiYun.project.api.slideshow.model.slidesShowModel;
import com.zhuiYun.project.api.slideshow.service.slidesShowService;
import com.zhuiYun.project.common.errorCode.CommonError;
import com.zhuiYun.project.common.response.CommonConstants;
import com.zhuiYun.project.common.response.CommonResult;
import com.zhuiYun.project.util.pageUtil.PageRequest;
import com.zhuiYun.project.util.pageUtil.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@CrossOrigin
@Api(tags = "轮播图管理")
@RequestMapping("/show")
/**
 * @Author 小江
 * @Description //TODO 轮播图
 * @Date 9:03 2023/4/5
 **/
public class slidsshowController {

    @Autowired
    slidesShowService slidesShowservice;

    /**
     * @Author 小江
     * @Description //TODO 轮播图全查
     * @Date 9:03 2023/4/5
     **/
    @GetMapping("slidsShowList")
    @ApiOperation(value = "轮播图管理的查询方法")
    @OptLog(modular = "轮播图管理", type = CommonConstants.ADD, describe = "查询轮播图")
    CommonResult slidsShowList(PageRequest pageResult){
        PageResult pageResult1 =slidesShowservice.slidsShowList(pageResult);
        return CommonResult.ok(pageResult1);
    }

    
    /**
     * @Author 小江
     * @Description //TODO 删除轮播图
     * @Date 9:29 2023/4/5
     **/
    @ApiOperation(value = "轮播图管理的删除方法")
    @OptLog(modular = "轮播图管理", type = CommonConstants.ADD, describe = "删除轮播图")
    @DeleteMapping("slidshowDel")
    CommonResult slidshowDel(Integer id){
        int i = slidesShowservice.slidshowDel(id);
        if (i > 0) {
            return CommonResult.ok();
        } else {
            return CommonResult.error();
        }
    }

    
    
    /**
     * @Author 小江
     * @Description //TODO 添加图片
     * @Date 13:39 2023/4/5
     **/
    @PostMapping("/slideseAdd")
    @ApiOperation(value = "轮播图管理的新增方法")
    @OptLog(modular = "轮播图管理", type = CommonConstants.ADD, describe = "添加轮播图")
    public CommonResult publishSaveAdd(MultipartFile imageFile, slidesShowModel slidesShowModel ) {
        int i = slidesShowservice.slideseAdd(imageFile, slidesShowModel);
        if(i>0){
            return CommonResult.ok();
        }else{
            return CommonResult.error("添加失败");
        }

    }
}
